package common

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Res struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

func (r *Res) Success(c *gin.Context) {
	c.JSON(http.StatusOK, &Res{
		Code: 0,
	})
}
func (r *Res) Fail(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, &Res{
		Code: 1,
		Msg:  msg,
	})
}
func (r *Res) DataSuccess(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, &Res{
		Code: 0,
		Data: data,
	})
}
func (r *Res) DataFail(c *gin.Context, msg string, data interface{}) {
	c.JSON(http.StatusOK, &Res{
		Code: 1,
		Msg:  msg,
		Data: data,
	})
}
func (r *Res) DataSuccessWithMsg(c *gin.Context, msg string, data interface{}) {
	c.JSON(http.StatusOK, &Res{
		Code: 0,
		Msg:  msg,
		Data: data,
	})
}
func (r *Res) DataFailWithMsg(c *gin.Context, msg string, data interface{}) {
	c.JSON(http.StatusOK, &Res{
		Code: 1,
		Msg:  msg,
		Data: data,
	})
}
